package com.partners.configure.wechatmp;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import lombok.Getter;
import lombok.Setter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liangyongle
 * @date 2019-01-12
 */
@Getter
@Setter
@Configuration
public class WechatConfig {

    /**
     * 微信支付配置
     * @return WxPayConfig
     */
    @Bean
    public WxPayConfig payConfig(WechatPayProperties wechatPayProperties) {
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(wechatPayProperties.getAppId());
        payConfig.setMchId(wechatPayProperties.getMchId());
        payConfig.setMchKey(wechatPayProperties.getMchKey());
        payConfig.setKeyPath(wechatPayProperties.getKeyPath());

        return payConfig;
    }

    /**
     * 微信支付服务
     * @return WxPayService
     */
    @Bean
    public WxPayService wxPayService(WxPayConfig payConfig) {
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(payConfig);
        return wxPayService;
    }
}
